#include "3dmath.h"

Vector add_vectors(Vector pA, Vector pB)
{
    Vector c;

    c.v[0] = pA.v[0] + pB.v[0];
    c.v[1] = pA.v[1] + pB.v[1];
    c.v[2] = pA.v[2] + pB.v[2];

    return c;
}

Vector sub_vectors(Vector pA, Vector pB)
{
    Vector c;

    c.v[0] = pA.v[0] - pB.v[0];
    c.v[1] = pA.v[1] - pB.v[1];
    c.v[2] = pA.v[2] - pB.v[2];

    return c;
}

Vector div_vector(Vector pA, float pB)
{
    Vector c;

    c.v[0] = pA.v[0] / pB;
    c.v[1] = pA.v[1] / pB;
    c.v[2] = pA.v[2] / pB;

    return c;
}

Vector cross_product(Vector pA, Vector pB)
{
    Vector c;

    c.v[0] = pA.v[1] * pB.v[2] - pA.v[2] * pB.v[1];
    c.v[1] = pA.v[2] * pB.v[0] - pA.v[0] * pB.v[2];
    c.v[2] = pA.v[0] * pB.v[1] - pA.v[1] * pB.v[0];

    return c;
}

float length(Vector pA)
{
    float l;

    l = sqrt(pA.v[0] * pA.v[0] + pA.v[1] * pA.v[1] + pA.v[2] * pA.v[2]);

    return l;
}

Vector unit(Vector pA)
{
    float l;

    l = length(pA);
    pA = div_vector(pA, l);

    return pA;
}

Vector normal(Vector pA, Vector pB, Vector pC)
{
    Vector n;

    n = cross_product(sub_vectors(pA, pC), sub_vectors(pB, pC));
    n = unit(n);

    return n;
}

Vector vector(float pX, float pY, float pZ)
{
    Vector a;

    a.v[0] = pX;
    a.v[1] = pY;
    a.v[2] = pZ;

    return a;
}
